import java.io.File;

// 7273
public class P67 {
	public static void main(String[] args) {
		int[][] m = new int[100][100];
		
		String content = Util.getContent(new File("triangle.txt"), true);
		String[] lines = content.split("\\n");
		
		for (int i = 0; i < lines.length; i++) {
			String line = lines[i];
			String[] value = line.split(" ");
			for (int j = 0; j < value.length; j++) {
				String v = value[j];
				m[i][j] = Integer.parseInt(v, 10);			
			}
			
			int max = 0;
			for (int j = 0; j < m[i].length; j++) {
				if (max < m[i][j]) {
					max = m[i][j];
				}
			}			
		}
		
		for (int i = 98; i >= 0; i--) {
			for (int j = 0; j <= i; j++) {
				m[i][j] += Math.max(m[i + 1][j], m[i + 1][j + 1]);
			}			
		}
		
		System.out.println(m[0][0]);
	}	
}
